package nicg.st.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import nicg.st.service.UserService;
import nicg.st.util.ErrorCode;
import nicg.st.util.ResponseUtil;

@RestController
@RequestMapping("/api/zzpguser")
public class UserController {

	@Autowired
	UserService userService;

	/**
	 * 返回当前登录的用户ID信息
	 * 
	 * @return
	 */
	@RequestMapping(value = "/getCurUserId", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public String getCurUserId() {
		if (userService.getCurUserId() == null) {
			return ResponseUtil.getResponseString(ErrorCode.SUCCESSFUL, "获取当前用户成功", userService.getCurUserId());
		} else {
			return ResponseUtil.getResponseString(ErrorCode.ERROR, "获取当前用户失败", userService.getCurUserId());
		}
	}

	/**
	 * 根据用户ID返回用户的身份信息（“旅”/“分队”）
	 * 
	 * @param userId
	 * @return
	 */
	@RequestMapping(value = "/getUserInfo", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public String getUserInfo(String userId) {
		if (userService.getUserInfo(userId) == null) {
			return ResponseUtil.getResponseString(ErrorCode.SUCCESSFUL, "获取当前用户信息失败", userService.getUserInfo(userId));
		} else {
			return ResponseUtil.getResponseString(ErrorCode.SUCCESSFUL, "获取当前用户信息成功", userService.getUserInfo(userId));
		}
	}

	/**
	 * 根据USERID返回用户的IP信息
	 * 
	 * @param userId
	 * @return
	 */
	@RequestMapping(value = "/getUserLoginVehIP", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public String getUserLoginVehIP(String userId) {
		if (userService.getUserLoginVehIP(userId) == null) {
			return ResponseUtil.getResponseString(ErrorCode.SUCCESSFUL, "获取当前用户IP失败",
					userService.getUserLoginVehIP(userId));
		} else {
			return ResponseUtil.getResponseString(ErrorCode.ERROR, "获取当前用户IP成功", userService.getUserLoginVehIP(userId));
		}
	}
}